import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from '../views/Login.vue'
import Register from '../views/Register.vue'
import Home from '../views/Home.vue'

import documentList from '../views/documentBrowse/documentList.vue'
import documentUpLoad from '../views/documentCenter/documentUpLoad.vue'
import documentAudit from '../views/documentCenter/documentAudit.vue'
import documentDelete from '../views/documentCenter/documentDelete.vue'
import userDocument from '../views/documentCenter/userDocument.vue'
import adminDocument from '../views/documentCenter/adminDocument.vue'

import myHome from '../views/myCenter/myHome.vue'
import myInformation from '../views/myCenter/myInformation.vue'
import changePswd from '../views/myCenter/changePswd.vue'

Vue.use(VueRouter)

const originalPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}

const routes = [
  {
    path: '/',
    name: 'Login',
    component: Login
  },
  {
    path: '/Register',
    name: 'Register',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "about" */ '../views/Register.vue')
  },
  {
    path: '/Home',
    name: 'Home',
    component: Home,
    meta: {
      requireAuth: true,
    },
    children: [
      {
        path: '/Home/index',
        name: 'documentList',
        component: documentList,
      },
      {
        path: '/myHome',
        name: 'myHome',
        component: myHome,
        children: [
          {
            path: '/myHome/myInformation',
            name: 'myInformation',
            component: myInformation
          },
          {
            path: '/myHome/changePswd',
            name: 'changePswd',
            component: changePswd
          }
        ]
      },
      {
        path: '/documentAudit',
        name: 'documentAudit',
        component: documentAudit,
        children: [
          {
            path: '/documentAudit/documentUpLoad',
            name: 'documentUpLoad',
            component: documentUpLoad
          },
          {
            path: '/documentAudit/documentDelete',
            name: 'documentDelete',
            component: documentDelete
          },
          {
            path: '/documentAudit/userDocument',
            name: 'userDocument',
            component: userDocument
          },
          {
            path: '/documentAudit/adminDocument',
            name: 'adminDocument',
            component: adminDocument
          },
        ]
      },

    ]
  }
]



const router = new VueRouter({
  mode: 'hash',
  routes
})

export default router
